package com.example.springboottools.test.pic;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import javax.sql.DataSource;

public class DataSourceConfig {
    private static HikariDataSource dataSource;

    static {
        HikariConfig config = new HikariConfig();
        config.setDriverClassName("oracle.jdbc.driver.OracleDriver");
        config.setJdbcUrl("jdbc:oracle:thin:@10.10.5.225:1521:TSCD");
        config.setUsername("staples");
        config.setPassword("staples2323W");
        config.addDataSourceProperty("cachePrepStmts", "true");
        config.addDataSourceProperty("prepStmtCacheSize", "250");
        config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
        config.setConnectionTimeout(30000); // 30秒
        config.setIdleTimeout(600000); // 10分钟
        config.setMaxLifetime(1800000); // 30分钟
        config.setMinimumIdle(10);
        config.setMaximumPoolSize(20);
        config.setValidationTimeout(5000); // 5秒
        config.setLeakDetectionThreshold(30000); // 30秒
        config.setConnectionTestQuery("SELECT 1 from dual"); // 用于验证连接的SQL查询
        config.setValidationTimeout(5000); // 5秒
        config.setAutoCommit(true);
        dataSource = new HikariDataSource(config);
    }

    public static DataSource getDataSource() {
        return dataSource;
    }
}
